<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <form action="">
        <!--pattern必须-->
        <!--<input type="text" pattern="/d{8,12}">-->
        <!--电话号码-->
        <input type="text" pattern="^1[3|5|7|8]\d{9}$">

        <input type="submit" value="提交"> 
    </form>


    <script>
        //截乘
        function jiecheng(n) {
            if (!(n > 0 && Math.floor(n))) {
                return NaN
            }
            var result = 1;
            for (var i = 2; i <= n; i++) {
                result = result * i
            }
            return result
        }
        var m = jiecheng(6)
        console.log(m)

        //质数
        function isPrime(n) {
            if (n < 2) {
                return false
            }
            if (n == 2) {
                return true
            }
            for (var i = 2; i < n; i++) {
                if (n % i == 0) {
                    return false
                }
            }
            return ture;
        }
        var p = isPrime(9)
        console.log(p)

        //互换变量的值
        var a = 3;
        var b = 5;

        //  var c = a
        //   a = b
        //   b = c
       a = b-a
       b = b-a
       a = a+b
        
         

        console.log(a)
        console.log(b)
        // console.log(c)


        //斐波那契数列
        function feibonaci(n){
            if(n<3){
                return n;
            }
            let n1 = 1;
            let n2 = 2;
            let temp;
            for(let i=3;i<=n;i++){
                 temp = n1+n2;
                 n1 = n2;
                 n2 = temp;
            }
            return temp;
        }
        feibonaci(4)
        console.log(feibonaci(4));

        //数组筛选   
        let str = "kdjfhsafkllkjdgshjlfha"
        function countString(s){
            var res = {}
            for(let i=0;i<s.length;i++){
                let ch = s[i]
                if(res[ch]){
                    res[ch]++;
                }
                else{
                    res[ch] = 1;
                }
            }
            // return res
        }

        console.dir(countString(str))

        //正则表达式  用于判断字符串是否匹配某种格式
        //\d  表示数字
        //\w  表示数字字母下划线
        //a-z 表示所有小写字母
        //A-Z 表示所有大写字母
        //+表示匹配一位或者多位
        // [\u4e00-\u9fa5]匹配中文字符
        var phone = "17630107763";
        var reg =/^1[3|5|7|8]\d{9}$/
        console.log(reg.test(phone))
        //单词统计
        var song = "lss ldfm sdsd hsdba,ashbd adbha"
        // var s = "lsdn|ksdaln,jnk|4444"
        // var arr = s.split(/\||,/)
        // console.log(arr)
        function countWord(s){
            var arr = song.split(/\s|,|\.|!|\?/)
            var res = {}
            arr.forEach(function(w){
                if(res[w]){
                    res[w]++
                }
                else{
                    res[w]=1
                }
            })
            return res
        }
        console.dir(countWord(song))

          
    </script>
</body>

</html>